//
//  MeVC.swift
//  旅航ios
//
//  Created by tulip on 2021/4/21.
//

import UIKit

class MeVC: UIViewController, UITableViewDelegate, UITableViewDataSource {
   
    
    @IBOutlet weak var boxImg: UIImageView!
    
    @IBOutlet weak var vipBtn: UIButton!
    @IBOutlet weak var boxview: UIImageView!
    @IBOutlet weak var photo: UIImageView!
    @IBOutlet weak var name: UILabel!
    @IBOutlet weak var table: UITableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.view.backgroundColor=UIColor.init(hexString: "f7f7f7")
        
//        DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
//            self.boxviwe.clickCorner(width: self.boxviwe.frame.size.width, height: self.boxviwe.frame.size.height, corners: corner, cornerRadii:CGSize(width: 24, height: 24))
//        }
        // 圆角位置
      
        
        vipBtn.setTitleColor(UIColor.init(hexString: "ffe09e"), for: .normal)
        vipBtn.layer.cornerRadius=13
        vipBtn.layer.borderColor=UIColor.init(hexString: "ffe09e").cgColor
        vipBtn.layer.borderWidth=0.5
        
        table.delegate=self
        table.dataSource=self
        table.bounces=false
        table.showsVerticalScrollIndicator=false
        table.register(UINib(nibName: "Me_OrderCell", bundle: nil), forCellReuseIdentifier: "Me_OrderCell")
        table.register(UINib(nibName: "Me_ServeCell", bundle: nil), forCellReuseIdentifier: "Me_ServeCell")
        table.estimatedRowHeight=170
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        2
    }
    
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.row == 0 {
            let cell:Me_OrderCell=tableView.dequeueReusableCell(withIdentifier: "Me_OrderCell", for: indexPath) as! Me_OrderCell
            return cell
            
    
        }
        
        let cell:Me_ServeCell=tableView.dequeueReusableCell(withIdentifier: "Me_ServeCell", for: indexPath) as! Me_ServeCell
        return cell
    }
    
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableView.automaticDimension
    }

    
    @IBAction func lookforRight(_ sender: Any) {
        let vc = RVRuleViewController()
        navigationController?.pushViewController(vc, animated:true)
        
        
    }
    
    @IBAction func set(_ sender: Any) {
        let vc=SetVC.init()
        vc.hidesBottomBarWhenPushed=true
        self.navigationController?.pushViewController(vc, animated: true)
        
    }
    
    override func viewWillAppear(_ animated: Bool) {
        self.navigationController?.navigationBar.isHidden=true
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        self.navigationController?.navigationBar.isHidden=false
    }
    
    func clickCantactBtn() {
        
        NetWorkRequest(API1.contactUS) { json in
            
            let mobile = json["data"]["mobile"].stringValue
            let allString = "tel://=" + mobile
            
            let  url = NSURL(string: allString)
            guard let uxx = url else {
                return
            }
            if UIApplication.shared.canOpenURL(uxx as URL) {
                
                let alertController = UIAlertController(title: mobile, message: nil, preferredStyle: .alert);
                
                let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil)
                let okAction = UIAlertAction(title: "确定", style: .default) { (action) in
                    
                    let app = UIApplication.shared
                    app.openURL(uxx as URL)
                    //打电话
                }
                
                alertController.addAction(cancelAction)
                alertController.addAction(okAction)
                self.present(alertController, animated: true, completion: nil)
                
            }
            
            
            
        } failed: { msg in

        } errorResult: {
        }
        
        
    }
    
    
}
